package com.shanghaionstar.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;

import com.onstar.cn.common.log.LogManager;
import com.onstar.cn.framework.mvp.base.core.BaseActivity;
import com.onstar.cn.framework.mvp.base.core.BasePresenter;

/**
 * Created by 7828wc on 16/8/17.
 */
public class ShareSOSMessageActivity extends BaseActivity {
    LogManager Log = LogManager.getInstance();

    @Override
    public BasePresenter getPresenter() {
        return null;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LogManager.getInstance().d("into SharePartnerActivity...............");

        Uri uri = getIntent().getData();
        if (uri.getScheme().equals("sos.m")) {
            parseToH5(uri);
        } else {
            Intent intent = new Intent(this, LoadingActivity.class);
            startActivity(intent);
            finish();
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        this.setIntent(intent);
    }


    private void parseToH5(Uri uri) {
        if (uri != null) {
            // 完整的url信息
            String realUrl = uri.getQueryParameter("url");
            if (!TextUtils.isEmpty(realUrl)) {
                Intent it = new Intent(this, LoadingActivity.class);
                it.putExtra("receiveType", "100");
                if (!realUrl.startsWith("http")) {
                    it.putExtra("uri", "http://" + realUrl);
                } else {
                    it.putExtra("uri", realUrl);
                }
                it.putExtra("title", "");
                startActivity(it);
                finish();

//                WebDataEntity entity = new WebDataEntity();
//                entity.setLinkUrl(realUrl);
//                entity.setCanGoBack(true);
//                CommonWebViewActivity.launchCommonWeb(SharePartnerActivity.this, entity);
//                finish();
            }
//            Log.e("url: " + uri);
//            // scheme部分
//            String scheme = uri.getScheme();
//            Log.e("scheme: " + scheme);
//            // host部分
//            String host = uri.getHost();
//            Log.e("host: " + host);
//            //port部分
//            int port = uri.getPort();
//            Log.e("host: " + port);
//            // 访问路劲
//            String path = uri.getPath();
//            Log.e("path: " + path);
//            List<String> pathSegments = uri.getPathSegments();
//            Intent intent = new Intent(this, LoadingActivity.class);
//            startActivity(intent);
//            finish();
        }
    }
}
